package com.kunbo.cn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@SpringBootApplication
@ServletComponentScan//扫描配置的servlet
@EntityScan({"com.bstek.uflo.model","com.kunbo.cn.entity","com.kunbo.cn.app.entity"})
@ImportResource(locations = {"classpath:uflo-console-context.xml"})
@EnableJpaAuditing//开启数据修改的时间注解
@EnableScheduling//定时器注解
public class Spu01Application {

	public static void main(String[] args) {
		SpringApplication.run(Spu01Application.class, args);
		System.out.println("恭喜您《启动成功了，，，，，，，，，，，，，，");
	}
	
	/**
	 * 
	 * <p>Title: corsFilter</p>
	 * <p>Description:解决端口跨域问题 </p>
	 * @return
	 */
	@Bean
    public CorsFilter corsFilter() {
        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(false);
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.addAllowedMethod("OPTIONS");
        config.addAllowedMethod("HEAD");
        config.addAllowedMethod("GET");
        config.addAllowedMethod("PUT");
        config.addAllowedMethod("POST");
        config.addAllowedMethod("DELETE");
        config.addAllowedMethod("PATCH");
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
	/**
	 * 
	 * <p>Title: containerCustomizer</p>
	 * <p>Description:设置session有效时间 </p>
	 * @return
	 */
	@Bean	
	public EmbeddedServletContainerCustomizer containerCustomizer() {
			return new EmbeddedServletContainerCustomizer() {
				@Override
				public void customize(ConfigurableEmbeddedServletContainer container) {				
				container.setSessionTimeout(1800);// 单位为S
				}

			};
	}


}

